function [ s_next, reward, eoe ] = DoAction(mdp, s, a)
%MountainCarDoAction: executes the action (a) into the mountain car
%environment
% a: is the force to be applied to the car
% s: is the vector containning the position and speed of the car
% s_next: is the vector containing the new position and velocity of the car


position = s(1);
speed    = s(2); 

% bounds for position
bpleft=mdp.x_range(1); 
bpright=mdp.x_range(2); 
bsleft=mdp.y_range(1); 
bsright=mdp.y_range(2); 

 
speedt1= speed + (0.001*a) + (-0.0025 * cos( 3.0*position) );	 
%speedt1= speedt1 * 0.999; % thermodynamic law, for a more real system with friction.

if(speedt1<bsleft) 
    speedt1=bsleft; 
end
if(speedt1>bsright)
    speedt1=bsright; 
end

post1 = position + speedt1; 

if(post1<=bpleft)
    post1=bpleft;
    speedt1=0.0;
end

if(post1>=bpright)
    reward = 100;
    eoe=true;
else
    reward = 0;
    eoe=false;
end
s_next=[post1 speedt1];






